<template>
    <div class="partadd">
    <el-row class="head">
        <el-col >——维修备件添加记录/报账单</el-col>
    </el-row>
        <el-row class="title">
            <el-col>维修备件添加记录</el-col>
        </el-row>
        <el-form  :model="partAdd" label-width="100px" class="formrule">
            <el-form-item label="备件名称">
                <el-select v-model="partAdd.partId" placeholder="全部">
                    <el-option
                            v-for="item in part"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                            >
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="维修人员">
                <el-select v-model="partAdd.adminId" placeholder="全部">
                    <el-option
                            v-for="item in admin"
                            :key="item.id"
                            :label="item.username"
                            :value="item.id"
                    >
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit(partAdd)">查询</el-button>
                <el-button  @click="fresh(partAdd)">重置</el-button>
            </el-form-item>
        </el-form>


        <el-table
                :data="form"
                border
                style="width: 100%">
            <el-table-column
                    prop="part.name"
                    label="备件名称"
                    width="380">
            </el-table-column>
            <el-table-column
                    prop="admin.username"
                    label="维修人员"
                    width="380">
            </el-table-column>
            <el-table-column
                    prop="number"
                    label="补充个数">
            </el-table-column>
            <el-table-column
                    prop="createdAt"
                    label="补充时间">
            </el-table-column>
        </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page.sync="partAdd.page.pageNum"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="10"
                layout="sizes, prev, pager, next"
                :total="total">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "partadd",
        data() {
            return {
                partAdd: {
                    adminId: '',
                    partId:'',
                    page: {
                        pageNum: 1,
                        pageSize:10
                    },
                },
                part:[],
                admin:[],
                form:[],
                total:0,
            }
        },
        created(){
            this.$axios.post("/api/v1/admin/part/listAll").then(result => {

                return result.data;
            })
                .then(data1 => {

                    this.part=data1.data;
                });
            this.$axios.post("/api/v1/admin/user/listAll").then(result => {

                return result.data;
            })
                .then(data1 => {

                    this.admin=data1.data;
                });
        },
        methods:{
            onSubmit(){
                this.$axios.post("/api/v1/admin/part/listadd",this.partAdd).then(result => {

                    return result.data;
                })
                    .then(data1 => {
                        console.log(data1.data);
                        this.form=data1.data.list;
                        this.total=data1._data.total;
                    });
            },
            fresh(data)
            {
                data.adminId="";
                data.partId="";
            },
            handleSizeChange(val) {

                this.partAdd.page.pageSize=val;
                this.onSubmit();
            },
            handleCurrentChange(val) {
                this.partAdd.page.pageNum=val;
                this.onSubmit();
            }

        }
    }
</script>

<style scoped>
    .el-input{
        width: 600px;
    }
</style>